<?php

require_once("../include/MySugarApplication.php");
require_once("../include/Account.php");
session_start();
$app->checkSession('Accounts/Save.php', $server_unique_key);

$id = $_REQUEST["id"];
$moduleName = $component->moduleName;

$actionType = isset($_REQUEST["actionType"]) ? $_REQUEST["actionType"] : "";

if ($actionType == "DELETE") {

	$result=$component->deleteRecord($id);

} else {

	$errors = array();


	if ($actionType == "UPDATE" && $id == "") {
		$errors["bitzer-global"] = "Cannot update when primary key is not passed";
	} else {

		$name = $_REQUEST["name"];

		if ($name == "")
			$errors["name"] = "Name is mandatory";
	
		$id = $_REQUEST["id"];
		$name = $_REQUEST["name"];
		$website = $_REQUEST["website"];
		$ticker_symbol = $_REQUEST["ticker_symbol"];
		$ownership = $_REQUEST["ownership"];
		$industry = $_REQUEST["industry"];
		$account_type = $_REQUEST["account_type"];
		$employees = $_REQUEST["employees"];
		$rating = $_REQUEST["rating"];
		$sic_code = $_REQUEST["sic_code"];
		$annual_revenue = $_REQUEST["annual_revenue"];
		$phone_office = $_REQUEST["phone_office"];
		$phone_fax = $_REQUEST["phone_fax"];
		$phone_alternate = $_REQUEST["phone_alternate"];
		$email1 = $_REQUEST["email1"];
		$billing_address_street = $_REQUEST["billing_address_street"];
		$billing_address_city = $_REQUEST["billing_address_city"];
		$billing_address_state = $_REQUEST["billing_address_state"];
		$billing_address_postalcode = $_REQUEST["billing_address_postalcode"];
		$billing_address_country = $_REQUEST["billing_address_country"];
		$shipping_address_street = $_REQUEST["shipping_address_street"];
		$shipping_address_city = $_REQUEST["shipping_address_city"];
		$shipping_address_state = $_REQUEST["shipping_address_state"];
		$shipping_address_postalcode = $_REQUEST["shipping_address_postalcode"];
		$shipping_address_country = $_REQUEST["shipping_address_country"];
		$description = $_REQUEST["description"];
		$date_modified = $_REQUEST["last_modified_on"];

		if (count($errors) == 0) {
			$result=$component->saveRecord($id, $name, $website, $ticker_symbol, $ownership,
									  $industry, $account_type, $employees, $rating, $sic_code,
									  $annual_revenue, $phone_office, $phone_fax, $phone_alternate, 
									  $email1, $billing_address_street, $billing_address_city, 
									  $billing_address_state, $billing_address_postalcode, 
									  $billing_address_country, $shipping_address_street,
									  $shipping_address_city, $shipping_address_state, 
									  $shipping_address_postalcode, $shipping_address_country, 
									  $description, $date_modified);
			if ($result != "" && $result["id"] != "")
				$id = $result["id"];
		}	     		  

	}
}

include("../include/SaveCommon.php");

?>
